package org.i1510.common.utils.encryption;

import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class Md5 {



	
	    /**
	    *@author bobolnear
	    *���ܣ�����ͬ���ķ�ʽ����
	    *@param origin
	    *@return 
	    * @version 1.0: Md5.java,v 1.1 Apr 1, 2009 11:19:16 AMBOBO-L-NEAR 
	    */
	    private synchronized static byte[] encode(String origin) {
	        byte[] hash = null;
	        try {
	            MessageDigest md = MessageDigest.getInstance("MD5");
	            md.reset();
	            hash = md.digest(origin.getBytes());
	        } catch (Exception ex) {
	            ex.printStackTrace();
	        }
	        return hash;
	    }

	    public synchronized static String getPassword(String origin) {
	        String result = "";
	        byte[] hash = Md5.encode(origin);
	        for (int i = 0; i < hash.length; i++) {
	            int itemp = hash[i]&0xFF;
	            if(itemp<16) result += "0";
	            result += Integer.toString(itemp, 16).toUpperCase();
	        }
	        return result;
	    }

	    public synchronized static boolean isPassword(String origin, String result) {
	        if (Md5.getPassword(origin).equals(result)) {
	            return true;
	        }
	        return false;
	    }
	   
	/**
	 *@author bobolnear
	 *���ܣ�
	 *@param args 
	 * @version 1.0: Md5.java,v 1.1 Mar 31, 2009 5:35:20 PMBOBO-L-NEAR 
	 */
	public static void main(String[] args) {
		 String result = "";
	        result = Md5.getPassword("1");
	        System.out.println(result);
	        
	        List list = new ArrayList();
	        for(int i = 0;i<2;i++){
	        	  Map selfResult = new HashMap();
	  			selfResult.put("account","1");//
	  			selfResult.put("quname", "2");//
	  			
	  			
	  			list.add(selfResult);
	        }
	      
			System.out.println(list);
	}

}
